<!--
 * @Description: 
 * @Date: 2024-06-25 21:24:10
 * @LastEditTime: 2024-09-14 14:55:32
-->
<!-- 使用 type="home" 属性设置首页，其他页面不需要设置，默认为page；推荐使用json5，更强大，且允许注释 -->
<route lang="json5">
{
  style: {
    navigationBarTitleText: '三务公开',
  },
}
</route>
<template>
  <view class="bg-white overflow-hidden pt-2 px-5">
    <view class="flex flex-col bg-#fff">
      <view class="text-32rpx tracking-0.1em">
        {{ baseData.title }}
      </view>
      <view
        class="flex justify-between items-center my-20rpx pb-20rpx b-b-solid b-b-1rpx b-b-#E8E8E8"
      >
        <view class="flex items-center">
          <!-- <view
            class="px-20rpx py-6rpx border-rd-30rpx text-26rpx bg-#F9E1C9 color-#D35B35 mr-20rpx"
          >
            收支状况
          </view> -->
          <text class="mr-20rpx text-#717171">发布日期</text>
          <text class="text-26rpx text-#717171">
            {{ formatTime(baseData.createTime, 'yyyy-MM-dd HH:mm:ss') }}
          </text>
        </view>
        <view class="text-26rpx"></view>
      </view>
      <!-- <wd-divider></wd-divider> -->
      <view class="p-10px">
        <rich-text
          :nodes="dealTxt(baseData.content)"
          :data-nodes="dealTxt(baseData.content)"
          @click="bigDetail"
        ></rich-text>
        <!-- <view v-html="dealTxt(baseData.content)" @click="bigDetail"></view> -->
      </view>
    </view>
  </view>
</template>

<script lang="ts" setup>
import { formatTime, dealTxt } from '@/utils/index'
import { getDisclosureAffairs } from '@/service/threeAffairs/index'
defineOptions({
  name: 'Home',
})
const baseData = ref({
  author: undefined,
  content: undefined,
  createTime: undefined,
  id: undefined,
  imageUrl: undefined,
  labelType: undefined,
  largeScreen: undefined,
  pushTime: undefined,
  readCount: undefined,
  source: undefined,
  stick: undefined,
  title: undefined,
  type: undefined,
})
// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()

// 测试 uni API 自动引入
onLoad(({ id }) => {
  getDisclosureAffairs(id).then((res) => {
    baseData.value = Object.assign(unref(baseData), res.data)
    baseData.value.content = dealTxt(baseData.value.content)
    console.log(baseData.value, 888)
  })
})
onUnload(() => {
  uni.$emit('refreshPage')
})
function bigDetail(e) {
  const contentimg = e.target.dataset.nodes
  const imgs = contentimg.match(/<img[^>]+>/g)
  const arrImg = []
  for (let i = 0; i < imgs.length; i++) {
    imgs[i].replace(/<img[^>]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {
      arrImg.push(capture)
    })
  }
  uni.previewImage({
    current: arrImg,
    urls: arrImg,
  })
}
</script>

<style>
.main-title-color {
  color: #d14328;
}
</style>
